import time

file1 = open("m1_sorted.txt")
file2 = open("m2_reverse.txt")
file3 = open("m3_shuffle.txt")

data1 = []
data2 = []
data3 = []

while True:
    string_f_1 = file1.readline()
    if not string_f_1:
        break
    data1.append(int(string_f_1))
while True:
    string_f_2 = file2.readline()
    if not string_f_2:
        break
    data2.append(int(string_f_2))
while True:
    string_f_3 = file3.readline()
    if not string_f_3:
        break
    data3.append(int(string_f_3))

#For 1 file
t_start_1 = time.time()
for i in range(len(data1)-1):
    for j in range(len(data1)-2,i-1,-1):
        if data1[j+1]<data1[j]:
            data1[j],data1[j+1]=data1[j+1],data1[j]
t_finish_1 = time.time()
print("m1_sorted",round((t_finish_1-t_start_1) *1000),"milliseconds")

#For 2 file
t_start_2 = time.time()
for i in range(len(data2)-1):
    for j in range(len(data2)-2,i-1,-1):
        if data2[j+1]<data2[j]:
            data2[j],data2[j+1]=data2[j+1],data2[j]
t_finish_2 = time.time()
print("m2_reverse",round((t_finish_2-t_start_2) *1000),"milliseconds")

#For 3 file
t_start_3 = time.time()
for i in range(len(data3)-1):
    for j in range(len(data3)-2,i-1,-1):
        if data3[j+1]<data3[j]:
            data3[j],data3[j+1]=data3[j+1],data3[j]
t_finish_3 = time.time()
print("m3_shuffle",round((t_finish_3-t_start_3) *1000),"milliseconds")
